<template>
  <div style="padding: 10px 15px">
    <!-- 查询条件-->
    <div class="filter-container">
      <el-input
        v-model="listQuery.title"
        placeholder="请输入单号"
        style="width: 300px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
    
      <el-button
        class="filter-item seachbttn"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
        >查询</el-button
      >
    </div>
    
    

    <!--查询条件 end-->

    <!--table-->
     <div>
      <el-table
      v-loading="listLoading"
      :data="PayRecordHelpData"
      fit
      highlight-current-row
      style="width: 100%"
      stripe
      height="500"
    >
    <el-table-column label="时间" align="left" min-width="200px">
        <template slot-scope="{ row }">
          <span>{{ row.dtCreateTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="错误信息" align="left" min-width="650px">
        <template slot-scope="{ row }">
          <span>{{ row.msg }}</span>
        </template>
      </el-table-column>
    </el-table>
     </div>


    <!--table end -->

    <!--弹出层 end-->
  </div>
</template>


<script>
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import { AjaxToken, TipConfirm } from "@/api/common";
import { SelectAjax } from "@/api/common";
import { Jurisdiction } from "@/api/common";
import sessionStorage from "@/api/Storage";
import "url-search-params-polyfill";
import commconfig from "@/comm.json";
export default {
  props: {
    error_msg: null,
  },
  name: "error_msg",
  components: { Pagination },
  watch: {
    error_msg: {
      deep: true,
      handler(val) {
       
        this.fetchData();
      },
    },
  },
  methods: {
    
    Export(Export) {
      if (Export) {
        this.downloadform.allexportLoading = true;
      } else {
        this.downloadform.nowexportLoading = true;
      }
      backstage.PayRecordHelpExport(this, Export);
    },
    //权限
    Jurisdiction(moduleActionName) {
      return Jurisdiction(moduleActionName, this);
    },
    //多选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //多选赋值
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    //搜索
    handleFilter() {
      this.listQuery.page = 1;
      this.fetchData();
    },
    //新增
    handleCreate() {
      this.dialogStatus = "create";
      this.dialogFormVisible = true;
    },
    //编辑
    handleClick(row) {
      this.dialogStatus = "edit";
      this.dialogFormVisible = true;
    },
    //保存
    saveForm() {
      var arr = this.multipleSelection;
      var params = new URLSearchParams();
      backstage.SavePayRecordHelp(this, params);
    },
    //删除
    deleteClick(row) {
      var multis = [];
      var params = new URLSearchParams();
      if (row == undefined || row == "") {
        var arr = this.multipleSelection;
        if (arr == undefined || arr.length <= 0) {
          this.$message({
            showClose: true,
            message: "请至少选中一行",
            type: "error",
          });
          this.listLoading = false;
          return;
        } else {
          for (var i = 0; i < arr.length; i++) {
            multis.push(arr[i].id);
          }
          params.append("delds", JSON.stringify(multis));
        }
      } else {
        multis.push(row.id);
        params.append("delds", JSON.stringify(multis));
      }
      this.$confirm("确认删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "error",
      })
        .then((a) => {
          this.listLoading = true;
          backstage.DelPayRecordHelp(this, params);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
          this.listLoading = false;
        });
    },
    //查询
    fetchData() {
      this.listLoading = true;
      var params = new URLSearchParams();
      params.append(
        "Parms",
        '{"page":' +
          this.listQuery.page +
          ',"rows":' +
          this.listQuery.limit +
          "}"
      );
      var user = JSON.parse(sessionStorage.getItem("userinfo"));
    
      params.append("order_id", this.listQuery.title==""?this.error_msg.orderid:this.listQuery.title);
     
      backstage.GetPayRecordHelpLst(this, params);
    },
  },

  //初始化
  created() {
    var userinfo = JSON.parse(sessionStorage.getItem("userinfo"));
    this.user = userinfo;
    this.logincpnid = userinfo.cpnId;
    backstage.GetEnum_PayStatuss(this);
    backstage.GeCpntListItems(this);
    this.fetchData();
  },
  activated() {
    var userinfo = JSON.parse(sessionStorage.getItem("userinfo"));
    this.user = userinfo;
    this.logincpnid = userinfo.cpnId;
    backstage.GeCpntListItems(this);
    backstage.GetEnum_PayStatuss(this);
    this.fetchData();
  },
  data() {
    return {
      Stt: "",
      user: null,
      SttOptions: [],
      sy: "system",
      logincpnid: "",
      cpnoptions: [],
      multipleSelection: [],
      formLabelWidth: "120px",
      PayRecordHelpData: null,
      listQuery: {
        title: "",
        total: 0,
        page: 1,
        limit: 10,
      },
      form: {
        StDt: "",
        EdDt: "",
        cpnID: "",
      },
      exportFormVisible: false,
      downloadform: {
        allexportLoading: false,
        nowexportLoading: false,
      },
      listLoading: true,
      dialogFormVisible: false,
      dialogdetailsVisible: false,
      dialogStatus: "",
      textMap: {
        update: "修改",
        create: "添加",
      },
    };
  },
};
//后台事件
var backstage = {
  PayRecordHelpExport: function (thisobj, Export) {
    var StDt =
      thisobj.form.StDt == "" ? "" : thisobj.form.StDt.toLocaleDateString();
    var EdDt =
      thisobj.form.EdDt == "" ? "" : thisobj.form.EdDt.toLocaleDateString();
    var PayID = thisobj.listQuery.title;
    var CpnID =
      thisobj.logincpnid == "sysytem" ? this.form.cpnID : thisobj.logincpnid;
    var Stt =
      thisobj.$route.query.tp == undefined
        ? thisobj.Stt
        : thisobj.$route.query.tp == "day"
        ? -1
        : thisobj.$route.query.tp == "moth"
        ? -2
        : "";
    var url =
      commconfig.baseapi +
      "PayRecordHelpExport?Parms=" +
      '{"page": "' +
      thisobj.listQuery.page +
      '","rows": "' +
      thisobj.listQuery.limit +
      '"}' +
      "&Export=" +
      Export +
      "&StDt=" +
      StDt +
      "&EdDt=" +
      EdDt +
      "&Stt=" +
      Stt +
      "&PayID=" +
      PayID +
      "&CpnID=" +
      CpnID;
    if (Export) {
      thisobj.downloadform.allexportLoading = false;
    } else {
      thisobj.downloadform.nowexportLoading = false;
    }
    window.location.href = url;
  },
  //获取PayRecordHelp集合
  GetPayRecordHelpLst: function (thisobj, params) {
    AjaxToken(
      thisobj,
      "GetPayRecordHelpLst_Error",
      params,
      "post",
      function (res) {
        thisobj.listLoading = false;
        var body = res.data.data;
        thisobj.PayRecordHelpData = body.rows;
        thisobj.listQuery.page = body.page;
        thisobj.listQuery.total = body.records;
      },
      function (err) {}
    );
  },
  GeCpntListItems: function (thisobj) {
    SelectAjax(
      "GeCpntListItems?val=" + thisobj.cpnid + "",
      function (response) {
        var body = response.data;
        thisobj.cpnoptions = [];
        body.data.forEach((element) => {
          thisobj.cpnoptions.push({
            value: element.value,
            label: element.text,
          });
        });
      },
      function (error) {}
    );
  },
  SavePayRecordHelp: function (thisobj, params) {
    AjaxToken(
      thisobj,
      "SavePayRecordHelp",
      params,
      "post",
      function (res) {
        var body = res.data;
        if (body.success) {
          thisobj.$message({
            showClose: true,
            message: body.message,
            type: "success",
            duration: 2000,
          });
          thisobj.fetchData();
          thisobj.dialogFormVisible = false;
        } else {
          thisobj.$message({
            showClose: true,
            message: body.message,
            type: "error",
          });
        }
      },
      function (err) {}
    );
  },
  DelPayRecordHelp: function (thisobj, params) {
    AjaxToken(
      thisobj,
      "DelPayRecordHelp",
      params,
      "post",
      function (res) {
        thisobj.listLoading = false;
        var body = res.data;
        if (body.success) {
          thisobj.$message({
            showClose: true,
            message: body.message,
            type: "success",
            duration: 2000,
          });
          thisobj.fetchData();
          thisobj.dialogFormVisible = false;
        } else {
          thisobj.$message({
            showClose: true,
            message: body.message,
            type: "error",
          });
        }
      },
      function (err) {}
    );
  },
  GetEnum_PayStatuss: function (thisobj) {
    SelectAjax(
      "GetEnum_PayStatuss?isEmpty=" + true + "+&code=0",
      function (response) {
        var body = response.data;
        thisobj.SttOptions = [];
        body.data.forEach((element) => {
          thisobj.SttOptions.push({
            value: element.value,
            label: element.text,
          });
        });
      },
      function (error) {}
    );
  },
};
</script>
<style scoped>
.app-main .pagination-container {
     margin-top: 0px; 
}
</style>